//是否在准备状态
let pending = false
//保存回调函数
, callbacks = []
, flushCallbacks = function(){
    pending = false;
    callbacks.forEach(callback=>{
        callback();
    })
    //清空数组
    callbacks.length = 0;
}
, nextTick = function(callback){
    callbacks.push(callback);
    if(!pending){
        pending = true;
        Promise.resolve().then(flushCallbacks)
    }
    return pending;
} 

nextTick(()=>{
    console.log(1)
})

nextTick(()=>{
    console.log(2)
})

console.log(3)